﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BusinessClass.StateMachine.Core
{
    /// <summary>
    /// 最后一个类型，如果错了，编译时不会报错
    /// </summary>
    /// <typeparam name="TlastReturn"></typeparam>
    [Obsolete("这个类会涉及类型转换，使用ContinueState替换吧。")]
    public class SequenceStates<TlastReturn> : ISate<TlastReturn>
        where TlastReturn : class
    {
        public ISate<object>[] States { get; private set; }
        public SequenceStates(params ISate<object>[] states)
        {
            States = states;
        }
        public TlastReturn Accept(Machine m)
        {
            int count = States.Length;
            foreach (var state in States.Take(count - 1))
            {
                m.Visit(state as ISate<object>);
            }
            return m.Visit(States.Last() as ISate<TlastReturn>);
        }
    }
}
